<?php
/**
 * 后台相关
 * @author fanzhanao
 *
 */
class cartoon_controller_admin_roll extends AdminController{
	public function __construct($app, $controller){
		parent::__construct($app, $controller);
		$this->data = Model::factory('cartoon_model_roll');
	}
	
	/**
	 * 添加修改
	 *
	 */
	public function add_action(){
		$args['title']	=	_('title');
		$args['info'] = _('info');
		$args['flag']	=	1;
		$args['link']	=	_('link');
		$args['add_time']	=	CURRENT_TIME;
		if($_FILES['imgurl'] && !$_FILES['imgurl']['error']){
			$path = 'rollimg/';
			$filename = md5(CURRENT_TIME.rand(1,10000));
			
			$rs = cartoon_util_upload::upload_file('imgurl',$path,substr($filename,0,rand(10,strlen($filenames)-10)));
			if($rs['result']){
				$args['img_url'] = UPLOAD_DOMAIN.'/'.$rs['url'];
			}
		}
		$this->data->add($args);
		/**
		 * 更新缓存
		 */
		cartoon_util_interface::cacheGetRoll(true);
		
		self::_redirect($this->app,$this->controller,'list');
		
	}
	
	/**
	 * 删除
	 *
	 */
	public function del_action(){
		$this->_renderJson();
		$id = _('id');
		if($this->data->remove($id)){
			/**
		 	 * 更新缓存
			 */
			cartoon_util_interface::cacheGetRoll(true);
			$this->ret = self::success();
		}else $this->ret = self::failure('删除失败');
	}
	
	public function list_action(){
		$page = _('page',1);
		
		$list = $this->data->getListPages($page,30);
		
		$pages = $this->genPages($list['INFO']);
		
		$this->ret = array('data'=>$list['ROWS'],'pages'=>$pages);
		
	}
}